<?php

namespace Budget\BudgetBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;
use Budget\BudgetBundle\Entity\Family;
use Budget\BudgetBundle\Entity\Expense;

class FilterStatisticType extends AbstractType
{
    const YEAR_START = 2014;

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $years       = range(self::YEAR_START, date('Y'));
        $yearOptions = array_combine($years, $years);

        $months       = range(1, 12);
        $monthOptions = array_combine($months, $months);
        $builder->add('year', 'choice', array(
            'choices' => $yearOptions,
            'label'   => 'Wybierz rok'
        ));

        $builder->add('month', 'choice', array(
            'choices'  => $this->getMonthsOptions(),
            'multiple' => true,
            'label'    => 'Wybierz miesiące'
        ));

        $builder->add('type', 'choice', array(
            'label'    => 'Typ',
            'choices'  => array('sum' => 'Suma', 'avg' => 'Średnia'),
            'expanded' => true,
        ));


        $builder->add('submit', 'submit', array('label' => 'Generuj'));
    }

    protected function getMonthsOptions()
    {
        $months = range(1, 12);
        $values = array();

        foreach ($months as $month) {
            $values[] = $month . ' - ' . date('F', mktime(0, 0 , 0 , $month, 1, 2011));
        }

        return array_combine($months, $values);
    }

    public function getName()
    {
        return 'filter_statistic';
    }
}

